# Contributor: Joe Searle <joe@jsearle.net>
# Maintainer: Joe Searle <joe@jsearle.net>
pkgname=boinc
pkgver=7.16.1
_pkgver=${pkgver%.*}
pkgrel=2
pkgdesc="Open-source software for volunteer computing and grid computing."
url="https://boinc.berkeley.edu/"
arch="all"
options="!check" # nothing is actually done by make check
license="LGPL-3.0-or-later"
depends="bash procps shadow"
makedepends="$depends_dev automake autoconf curl-dev docbook2x freeglut-dev
	glu-dev libjpeg-turbo-dev libnotify-dev openssl-dev libtool
	libxi-dev libxmu-dev libxscrnsaver-dev m4 mesa-dev pkgconf
	sqlite-dev wxgtk-dev"
install="$pkgname.pre-install"
pkgusers="boinc"
pkggroups="boinc"
subpackages="$pkgname-doc $pkgname-dev $pkgname-gui $pkgname-lang $pkgname-libs $pkgname-openrc $pkgname-screensaver"
source="boinc-$pkgver.tar.gz::https://github.com/BOINC/boinc/archive/client_release/$_pkgver/$pkgver.tar.gz"
builddir="$srcdir/$pkgname-client_release-$_pkgver-$pkgver"

build() {
	./_autosetup

	./configure \
		--build="$CBUILD" \
		--host="$CHOST" \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-server \
		--disable-fcgi \
		--enable-client \
		--enable-boinczip \
		--enable-install-headers \
		--enable-libraries \
		--with-x

	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

_cleanup_empty_dirs() {
	local _dir
	_dir="${1:-"$pkgdir"}"

	find "$_dir" -mindepth 1 -depth -type d -exec rmdir --ignore-fail-on-non-empty '{}' +
}

libs() {
	default_libs
	depends="$depends_libs"

	_cleanup_empty_dirs
}

gui() {
	depends="$depends_gui"
	pkgdesc="$pkgdesc (manager)"

	mkdir -p "$subpkgdir/usr/bin"
	mv "$pkgdir/usr/bin/boincmgr" "$subpkgdir/usr/bin"

	_cleanup_empty_dirs
}

screensaver() {
	depends="$depends_screensaver"
	pkgdesc="$pkgdesc (screensaver)"

	mkdir -p "$subpkgdir/usr/bin"
	mv "$pkgdir/usr/bin/boincscr" "$subpkgdir/usr/bin"

	_cleanup_empty_dirs
}

sha512sums="53d320564a4a7de1b4d47c5f9492a9180c2875f9910cd609d370217075790fa01627ea4ccb79b1e7216308ff9e8ad0c7974cd2df3ad81e0ef17133ee3782a221  boinc-7.16.1.tar.gz"
